home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Networking & Communications / Serial NB Sample Driver / Task / inc / interrupt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  3.6 KB  |  205 lines  |  [TEXT/MPS ]

  1. /********************************************************************************/
  2. /*                                                                                */
  3. /*        interrupt.c - SCC interrupt routines.                                    */
  4. /*                                                                                */
  5. /*        Richard W. Mincher.  February 19, 1990.                                    */
  6. /*                                                                                */
  7. /*        Copyright © 1990 Apple Computer, Inc.  All rights reserved.                */
  8. /*                                                                                */
  9. /*                                                                                */
  10. /*        Once the interrupt routines are complete it might be a good idea        */
  11. /*        to convert them to assembler.  It remains to be seen how much            */
  12. /*        improvement can actually be made.  MPW 3.1 is pretty good if you        */
  13. /*        don't have any complicated expressions or structure references.            */
  14. /*        My using of absolute references for globals seems to do nicely.            */
  15. /*                                                                                */
  16. /********************************************************************************/
  17.  
  18. #include    "AROSE.h"
  19. #include    "os.h"
  20. #include    "managers.h"
  21.  
  22. #include    "ARDriver.h"
  23. #include    "ARTask.h"
  24.  
  25. pascal    void illegal()
  26.     extern 0x4afc;
  27.  
  28. tbeint()
  29. {
  30.     ++(G->tbeCount);
  31.  
  32. //    See if we are to send XON or XOFF.
  33.  
  34.     if (G->sendXOnff)
  35.     {
  36.         *SCCData = G->sendXOnff;
  37.         G->sendXOnff = 0;
  38.         G->moreTx = 1;
  39.         return;
  40.     }
  41.  
  42. //    See if handshake is okay.
  43.  
  44.     if ((G->swhs && G->xOffFlag) || (G->hwhs && G->CTSFlag))
  45.     {
  46.         *SCCControl = 0x28;
  47.         G->moreTx = 0;
  48.         return;
  49.     }
  50.     
  51.     if (G->txCount)
  52.     {
  53.         --(G->txCount);
  54.         --(G->sTxCount);
  55.         if (G->txCount == 0)
  56.             G->moreTx = 0;
  57.         else
  58.             G->moreTx = 1;
  59.         *SCCData = *(G->txOut);
  60.         ++(G->txOut);
  61.         if (G->txOut == G->txLast)
  62.             G->txOut = G->txFirst;
  63.         
  64.         if ((G->txCount == 0) || (G->txTickle && (--(G->txTickle) == 0)))
  65.         {
  66.             if (G->txSignal)
  67.             {
  68.                 Send( G->txSignal );
  69.                 G->txSignal = 0;
  70.             }
  71.             else
  72.                 illegal();
  73.         }
  74.         return;
  75.     }
  76.  
  77.     *SCCControl = 0x28;
  78.     G->moreTx = 0;
  79. }
  80.  
  81. escint()
  82. {
  83.     unsigned char    stat, chg;
  84.     
  85.     ++(G->escCount);
  86.     stat = *SCCControl;
  87.     chg = stat ^ G->prevStat;
  88.     G->prevStat = stat;
  89.     *SCCControl = 0x10;
  90.  
  91.     if (chg & 0x20)    /*    CTS        */
  92.     {
  93.         G->CTSFlag = (stat & 0x20);
  94.         if (G->hwhs && !G->CTSFlag)
  95.             tbeint();
  96.     }
  97.     
  98.     if (chg & 0x80)    /*    Break    */
  99.     {
  100.         /*    Terminate input request    */
  101.     }
  102. }
  103.  
  104. rcaint()
  105. {
  106.     unsigned char    c;
  107.     
  108.     ++(G->rcaCount);
  109.  
  110. //    Get the data.
  111.  
  112.     c = *SCCData & G->charMask;
  113.  
  114. //    Check for PE substitution.
  115.     
  116.     if (G->peChar && (G->peChar == c))
  117.         c = G->altChar;
  118.  
  119. //    Check for software handshake XON.
  120.  
  121.     if (G->swhs && (G->xOnChar == c))
  122.     {
  123.         if (G->xOffFlag)
  124.         {
  125.             G->xOffFlag = 0;
  126.             tbeint();
  127.         }
  128.         return;
  129.         
  130.     }
  131.     
  132. //    Check for software handshake XOFF.
  133.  
  134.     if(G->swhs && (G->xOffChar == c))
  135.     {
  136.         G->xOffFlag = 1;
  137.         return;
  138.     }
  139.     
  140.     if (G->rxCount)
  141.     {
  142.         ++(G->sRxCount);
  143.         --(G->rxCount);
  144.         *(G->rxIn) = c;
  145.         ++(G->rxIn);
  146.         if (G->rxIn == G->rxLast)
  147.             G->rxIn = G->rxFirst;
  148.         
  149.         if ((G->rxCount == 0) || (G->rxTickle && (--(G->rxTickle) == 0)))
  150.         {
  151.             if (G->rxSignal)
  152.             {
  153.                 Send( G->rxSignal );
  154.                 G->rxSignal = 0;
  155.             }
  156.         }
  157.         return;
  158.     }
  159.  
  160.     G->asyncErr |= 1;    /*    Soft overrun    */
  161. }
  162.  
  163. srcint()
  164. {
  165.     unsigned char    err, c;
  166.     
  167.     ++(G->srcCount);
  168.     *SCCControl = 0x01;                /*    Point to RR1        */
  169.     err = *SCCControl;                /*    Get the error        */
  170.     G->asyncErr |= (err & 0x70);    /*    accumulate errors    */
  171.     c = *SCCData & G->charMask;        /*    Get the data        */
  172.     *SCCControl = 0x30;                /*    Reset the error        */
  173.     
  174.     if (G->options & err)
  175.     {
  176.         if (G->rxQHead)
  177.         {
  178.             /*    Abort current read    */
  179.         }
  180.         return;
  181.     }
  182.     
  183.     if (G->peChar && (G->peChar == c) && (err & 0x10))
  184.         c = G->altChar;
  185.  
  186.     if (G->rxCount)
  187.     {
  188.         ++(G->sRxCount);
  189.         --(G->rxCount);
  190.         *(G->rxIn) = c;
  191.         ++(G->rxIn);
  192.         if (G->rxIn == G->rxLast)
  193.             G->rxIn = G->rxFirst;
  194.         
  195.         if ((G->rxCount == 0) || (G->rxTickle && (--(G->rxTickle) == 0)))
  196.         {
  197.             if (G->rxSignal)
  198.             {
  199.                 Send( G->rxSignal );
  200.                 G->rxSignal = 0;
  201.             }
  202.         }
  203.     }
  204. }
  205.